<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ui:composition template="../Master/adminMaster.xhtml" >
            <ui:define name="page-content">
                <h:panelGroup rendered="#{login.customer.membersRole == 2}">
                    <h:form id="form" class="form">
                        <fieldset class="grey">
                            <legend>Edit member</legend>
                            <p:messages id="messages" showDetail="true" closable="true" autoUpdate="true" severity="info, warn"/>
                            <pe:tooltip global="true" myPosition="left center" atPosition="right center" forSelector=".ui-state-error"/>
                            <table border="0" cellpadding="0" cellspacing="0" id="id-form">
                                <tr>
                                    <th valign="top" class="id-form-th"><label>Member name<span class="required">*</span>:</label></th>
                                    <td class="id-form-td">
                                        <p:inputText value="#{memberBean.m.membersName}" id="membersName" required="true" 
                                                     styleClass="larger"
                                                     title="#{component.valid ? '' : memberBean.getErrorMessage(component.clientId)}">
                                            <f:validateLength minimum="3" maximum="200"/>
                                        </p:inputText>
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>

                                <tr>
                                    <th valign="top" class="id-form-th"><label>Department:</label></th>
                                    <td class="id-form-td">
                                        <h:selectOneMenu value="#{memberBean.departmentID}">
                                            <c:forEach var="dep" items="#{departmentMBean.departments}">
                                                <f:selectItem itemLabel="#{dep.departmentName}" itemValue="#{dep.departmentID}"/>
                                            </c:forEach>
                                        </h:selectOneMenu>     
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>
                                <tr>
                                    <th valign="top" class="id-form-th"><label>User name <span class="required">*</span>:</label></th>
                                    <td class="id-form-td">
                                        <p:inputText value="#{memberBean.m.membersUser}" id="membersUser" 
                                                     required="true" styleClass="larger"
                                                     title="#{component.valid ? '' : memberBean.getErrorMessage(component.clientId)}">
                                            <f:validateLength minimum="3" maximum="200"/>
                                        </p:inputText>
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>
                                <tr>
                                    <th valign="top" class="id-form-th"><label>Password <span class="required">*</span>:</label></th>
                                    <td class="id-form-td">
                                        <p:password id="membersPassword" value="#{memberBean.m.membersPassword}" title="#{component.valid ? '' : memberBean.getErrorMessage(component.clientId)}" styleClass="larger">
                                            <f:validateRegex pattern="((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,200})" />
                                        </p:password>
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>
                                <tr>
                                    <th valign="top" class="id-form-th"><label>Gender:</label></th>
                                    <td class="id-form-td">
                                        <h:selectOneMenu value="#{memberBean.m.membersGender}">
                                            <f:selectItem itemLabel="Male" itemValue="Male"></f:selectItem>
                                            <f:selectItem itemLabel="Female" itemValue="Female"></f:selectItem>
                                        </h:selectOneMenu>     
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>
                                <tr>
                                    <th valign="top" class="id-form-th"><label>Address:</label></th>
                                    <td class="id-form-td">
                                        <p:inputText value="#{memberBean.m.membersAddress}" styleClass="larger">
                                        </p:inputText>
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>
                                <tr>
                                    <th valign="top" class="id-form-th"><label>Phone<span class="required">*</span>:</label></th>
                                    <td class="id-form-td">
                                        <p:inputText id="membersPhone" value="#{memberBean.m.membersPhone}" 
                                                     label="Phone" styleClass="larger"
                                                     title="#{component.valid ? '' : memberBean.getErrorMessage(component.clientId)}">
                                            <f:validateRegex pattern="(([0-9]).{5,20})"/>
                                        </p:inputText>
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>

                                <tr>
                                    <th valign="top" class="id-form-th"><label>Position <span class="required">*</span>:</label></th>
                                    <td class="id-form-td">
                                        <p:inputText value="#{memberBean.m.membersPosition}" id="membersPosition" 
                                                     required="true" styleClass="larger"
                                                     title="#{component.valid ? '' : memberBean.getErrorMessage(component.clientId)}">
                                            <f:validateLength minimum="3" maximum="200"/>
                                        </p:inputText>  
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>

                                <tr>
                                    <th valign="top" class="id-form-th"><label>Member role:</label></th>
                                    <td class="id-form-td">

                                        <h:selectOneMenu  value="#{memberBean.m.membersRole}">
                                            <f:selectItem itemLabel="Member" itemValue="0"></f:selectItem>
                                            <f:selectItem itemLabel="Technician" itemValue="1"></f:selectItem>
                                            <f:selectItem itemLabel="Admin" itemValue="2" rendered="#{login.customer.membersRole==2}"></f:selectItem>
                                        </h:selectOneMenu>     
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>

                                <tr>
                                    <th class="id-form-th">&nbsp;</th>
                                    <td valign="top" class="id-form-td">

                                        <p:commandButton value="Save" actionListener="#{memberBean.editMembers}"
                                                         icon="ui-icon-disk" styleClass="grey"
                                                         update="form,form:messages" process="form"/>
                                        <p:commandButton type="reset" styleClass="grey" update="form,form:messages" value="Reset"/>
                                    </td>
                                    <td class="id-form-td"></td>
                                </tr>
                            </table>
                        </fieldset>   
                    </h:form>
                </h:panelGroup>
            </ui:define>
        </ui:composition>
    </h:body>
</html>

